package com.zxl.live.tools.alert;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.util.Log;

/**
 * 功能：
 * 作者： caijun
 * 时间： 2017/3/1  16 : 17
 */
public class HuaweiGotoAlertSet implements AlertPermissionUtils.GotoAlertManager {
    private static final String SCHEME = "package";

    @Override
    public void gotoAlert(Context context) {
        Intent intent = new Intent();
        if (isEmotionUI_31() || isEmotionUI_23() || isEUI_23()) {
            intent.setAction("huawei.intent.action.HSM_PROTECTED_APPS");
//            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        } else {
            intent.setClassName("com.huawei.systemmanager", "com.huawei.notificationmanager.ui.NotificationManagmentActivity");
//            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            Log.e("alter", "huawei alert permission intent exception : " + e.toString());
            try {
                Intent intent1 = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent1.setData(Uri.fromParts(SCHEME, context.getPackageName(), null));
                context.startActivity(intent1);
            } catch (Exception e1) {

            }
        }

    }

    public boolean isEmotionUI_31() {
        return "EmotionUI_3.1".equalsIgnoreCase(getRomName());
    }
    public boolean isEmotionUI_3() {
        return "EmotionUI_3.0".equalsIgnoreCase(getRomName());
    }
    @SuppressLint({"DefaultLocale"})
    public boolean isEmotionUI_23() {
        return "EmotionUI_2.3".equalsIgnoreCase(getRomName()) || Build.DISPLAY.toLowerCase().contains("emui2.3");
    }

    @SuppressLint({"DefaultLocale"})
    public boolean isEUI_23() {
        return "EMUI 2.3".equalsIgnoreCase(getRomName());
    }

    public String getRomName() {
        try {
            return get("ro.build.version.emui");
        } catch (Exception e) {
            return "";
        }
    }

    public String get(String str) {
        try {
            Class cls = Class.forName("android.os.SystemProperties");
            Object invoke = cls.getMethod("get", new Class[]{String.class}).invoke(cls, new Object[]{str});
            if (invoke == null || !(invoke instanceof String)) {
                return null;
            }
            return (String) invoke;
        } catch (Exception e) {
            return null;
        }
    }
}
